<?php

namespace App\Models;

use Illuminate\Database\Eloquent\Model;

class Order extends Model
{
    const UPDATED_AT ='updatedAt';

    const CREATED_AT = 'createdAt';


    protected $fillable = ['userId','companyId','orderNo','outTradeno','name','term','price','status','type','num','flag'];

    protected function getDateFormat()
    {
        return time();
    }
    protected $dates = [];

    public static $rules = [
        // Validation rules
    ];

    // Relationships
    //获取全部记录
    public function getList($userId, $input)
    {   
        $list = \DB::table('orders')->where('userId','=',$userId)
        ->where(function($query) use($input)
        { 
            if (!empty($input['searchVal'])) 
            {  
                $query->where('orderNo', '=', $input['searchVal'] )
                    ->orwhere('name','like','%' .$input['searchVal']. '%' );
            }
        })
        ->orderBy('updatedAt','desc')
        ->get()->toArray();
        return $list;
    }
}
